<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 300px;
            height: 500px;
            margin: 100px auto;
            border: 2px solid red;
        }
        .box div{
            width: 260px;
            height: 300px;
            background: pink;
            margin-top: 20px;
            margin-left: 20px;
        }
        .box p{
            height: 20px;
            line-height: 20px;
            width: 300px;
            text-align: center;
        }
        .box #price{
            font-size: 28px;
            line-height: 28px;
            color: red;
        }
        .box #input1{
            width: 20px;
            height: 20px;
            text-align: center;
        }
        .box #input2{
            width: 40px;
            height: 15px;
            text-align: center;
        }
        .box #input3{
            width: 20px;
            height: 20px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="box">
        <div></div>
        <p class="p1">xxxxxxxxXXX</p>
        <p>价格：<span id="price">299</span>元 </p>
        <p>
            数量
            <input type="submit" value="-" id="input1" >
            <input type="text" value="0" id="input2">
            <input type="submit" value="+" id="input3">
        </p>
        <p>总价格：<span id="total"></span>元</p>
    </div>
</body>
<script>
    var num = 0;
    input1.onclick = function(){
        if(num == 0){
            return;
        }
        num--;
        input2.value = num;
        total.innerHTML = num * price.innerHTML
    }
    input3.onclick = function(){
        num++;
        input2.value = num;
        total.innerHTML = num * price.innerHTML
    }
    input2.oninput = function(){
        num = input2.value;
        total.innerHTML = num * price.innerHTML;
    }
</script>
</html>